package kevin.newmybatis.mybatis.config;

import kevin.newmybatis.mybatis.session.SqlSession;
import kevin.newmybatis.mybatis.proxy.MapperProxy;

import java.lang.reflect.Proxy;

public class MyConfiguration {



//    private  SqlSession sqlSession;
//
//    public MyConfiguration(SqlSession sqlSession) {
//        this.sqlSession = sqlSession;
//    }

    /**
     * 通过动态代理获取Mapper
     * UserMapperXML直接使用代码替代xml
     * @param calss
     * @param <T>
     * @return
     */
    public <T>T getMapper(Class calss,SqlSession sqlSession) {

        return (T)Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class[]{calss}, new MapperProxy(sqlSession));
    }


//      static class  UserMapperXML{
//        public  static final  String mapper="kevin.newmybatis.mybatis.UserMapper";
//        public  static final Map<String,String> sqlMap  =new HashMap<String,String>();
//
//        static {
//            sqlMap.put("getFindById","select * from user where id=%d");
//        }
//    }


}
